﻿<?php
class Model_Catdes extends Zend_Db_Table_Abstract
{
		protected $_name = 'category_description';

		public function createCatdes ($cat_id,$catdes_ten)
		{
			$rowCatdes = $this->createRow();
			if ($rowCatdes) {
				// update the row values
				$rowCatdes->cat_id = $cat_id;
				$rowCatdes->catdes_ten = $catdes_ten;
				$rowCatdes->save();
				//return the new catdes
				return $rowCatdes;
			} else {
				throw new Zend_Exception("Không thể tạo category_description mới ");
			}
		}
		
	public static function getCatdes($cat_id)
	{
		$catdesModel = new self();
		$select = $catdesModel->select();
		$select->order(array('catdes_id'))
		       ->where('cat_id =?',$cat_id);	
		return $catdesModel->fetchAll($select);
	}

	public function updateCatdes($catdes_id,$cat_id,$catdes_ten)
	{
		// fetch the user's row
		$rowCatdes = $this->find($catdes_id)->current();
		//var_dump($rowUser);
		if($rowCatdes) {
			// update the row values
			$rowCatdes->cat_id = $cat_id;
			$rowCatdes->catdes_ten = $catdes_ten;
			$rowCatdes->save();
			//return the updated catdes
			return $rowCatdes;
		}else{
			throw new Zend_Exception("Không thể update. Không tìm thấy catdes.");
		}
	}

	public function deleteCatdes($cat_id)
	{
		// fetch the user's row
		$rowCatdes = $this->find($catdes_id)->current();
		if($rowUser) {
			$rowCatdes->delete();
		}else{
			throw new Zend_Exception("Không thể xóa catdes. Không tìm thấy!");
		}
	}
   public static function getCatdesDetail($catdes_id)
	{
		$catdesModel = new self();
		$select = $catdesModel->select();
		$select->order(array('catdes_id'))
		       ->where('catdes_id =?',$catdes_id);	
		return $catdesModel->fetchAll($select);
	}
}
